<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <!-- 控制浏览器缓存 -->
    <meta http-equiv="Cache-Control" content="no-store"/>
    <!-- 优先使用 IE 最新版本和 Chrome -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <title>星程支付</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        html,
        body {
            height: 100%;
            overflow: hidden;
        }

        .clearfix:after {
            content: "\200B";
            display: block;
            height: 0;
            clear: both;
        }

        .clearfix {
            *zoom: 1;
        }

        /*IE/7/6*/

        .form-amount div::-webkit-scrollbar {
            width: 0;
            height: 0;
            -webkit-transition: 1s;
        }

        .form-amount div::-webkit-scrollbar-thumb {
            background-color: #a7afb4;
            background-clip: padding-box;
            min-height: 28px;
        }

        .form-amount div::-webkit-scrollbar-thumb:hover {
            background-color: #525252;
            background-clip: padding-box;
            min-height: 28px;
        }

        .form-amount div::-webkit-scrollbar-track-piece {
            background-color: #ccd0d2;
        }

        .wrap {
            position: relative;
            margin: auto;
            max-width: 640px;
            min-width: 320px;
            width: 100%;
            height: 100%;
            background: #F0EFF5;
            overflow: hidden;
        }

        .layer-content {
            position: absolute;
            left: 50%;
            bottom: -200px;
            width: 100%;
            max-width: 640px;
            height: auto;
            z-index: 12;
            -webkit-transform: translateX(-50%);
            transform: translateX(-50%);
        }

        /* 输入表单 */

        .edit_cash {
            display: block;
            margin-top: 15px;
            padding: 15px;
            margin: 0 auto;
            width: 90%;
            border: 1px solid #CFCFCF;
            border-radius: 10px;
            background-color: #fff;
        }

        .edit_cash p {
            font-size: 14px;
            color: #8D8D8F;
        }

        .form-amount {
            position: relative;
            margin-bottom: 10px;
        }

        .form-amount div {
            border: none;
            width: 100%;
            height: 50px;
            font-size: 25px;
            line-height: 50px;
            border-bottom: 1px solid #CFCFCF;
            text-indent: 30px;
            outline: none;
            white-space: pre;
            overflow-x: scroll;
        }

        .form-amount span {
            position: absolute;
            top: 5px;
            font-size: 25px;
        }

        .submit {
            display: block;
            margin: 20px auto 0;
            width: 90%;
            height: 40px;
            font-size: 16px;
            color: #fff;
            background: #48d96b;
            border: 1px solid #47D14C;
            border-radius: 3px;
        }

        .bg {
            background: #46a6ff;
            border: 1px solid #477fd1;
        }

        /* 键盘 */

        .edit {
            width: 100%;
            background: #D1D4DD;
        }

        .edit > div {
            margin-bottom: 2px;
            margin-right: 0.5%;
            float: left;
            width: 33%;
            height: 45px;
            text-align: center;
            color: #333;
            line-height: 45px;
            font-size: 18px;
            font-weight: 600;
            background-color: #fff;
            border-radius: 5px;
        }

        .edit > div:nth-child(3n) {
            margin-right: 0;
        }

        .edit > div:last-child {
            background-color: #DEE1E9;
        }
    </style>
</head>
<body>
<div class="wrap">
    <div class="edit_cash">
        <p>消费总额</p>
        <div class="form-amount">
            <span>&yen;</span>
            <div id="amount"></div>
        </div>
        <p>可询问工作人员应支付费用</p>
    </div>
    <input type="submit" value="微信" id="wechat" class="submit"/>
    <input type="submit" value="支付宝" id="alipay" class="submit bg"/>
</div>
<div class="layer-content">
    <div class="edit clearfix">
        <div class="num">1</div>
        <div class="num">2</div>
        <div class="num">3</div>
        <div class="num">4</div>
        <div class="num">5</div>
        <div class="num">6</div>
        <div class="num">7</div>
        <div class="num">8</div>
        <div class="num">9</div>
        <div class="num">.</div>
        <div class="num">0</div>
        <div id="remove">删除</div>
    </div>
</div>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
<script>
    var ua = window.navigator.userAgent.toLowerCase();
    //判断是不是微信
    if (ua.match(/MicroMessenger/i) === 'micromessenger') {
    }
    //判断是不是支付宝
    if (ua.match(/AlipayClient/i) === 'alipayclient') {
    }
    var url = 'https://starltd.xingchengfu.com/index.php/pay/transaction.do';
//        var url = 'http://localhost/Star.Ltd/public/index.php/pay/transaction.do';
    var chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];

    function randomStr(n) {
        var res = "";
        for (var i = 0; i < n; i++) {
            var id = Math.ceil(Math.random() * 35);
            res += chars[id];
        }
        return res;
    }

    $(function () {
        var amount = $('#amount');
        var submit = $('.submit');
        amount.bind('DOMNodeInserted', function () {
            if (amount.text() !== "" || amount.text() > '0') {
                submit.removeClass('active');
                submit.attr('disabled', false);
            } else {
                submit.addClass('active');
                submit.attr('disabled', true);
            }
        });
        amount.trigger('DOMNodeInserted');
        $('.form-amount').click(function (event) {
            $('.layer-content').animate({
                bottom: 0
            }, 200);
            event.stopPropagation();
        });
        $('.wrap').click(function () {
            $('.layer-content').animate({
                bottom: '-200px'
            }, 200)
        });
        $('.edit .num').click(function () {
            var amount = document.getElementById("amount");
            amount.innerHTML += this.innerHTML;
        });
        $('#remove').click(function () {
            var amount = document.getElementById("amount");
            var old = amount.innerHTML;
            amount.innerHTML = old.substring(0, old.length - 1);
            var submit = $('.submit');
            if (amount.innerHTML === "" || amount.innerHTML <= '0') {
                submit.addClass('active');
                submit.attr('disabled', true);
            }
        });
        $("#alipay").click(function () {
            $.ajax({
                url: url,
                type: 'POST',
                data: {
                    user_id: 1234,
                    shop_id: 11,
                    amount: $("#amount").text(),
                    order_no: randomStr(16),
                    payment: "alipay",
                    callback: "http://",// 回调地址
                    other: {
                        body: 'iPhone 81', // 可选
                        title: '苹果81',// 可选
                        return_url: "https://starltd.xingchengfu.com",// 支付成功跳转的页面
                        quit_url: "https://starltd.xingchengfu.com"// 退出支付跳转的页面
                    }
                },
                timeout: 5000,
                dataType: 'json',
                beforeSend: function (xhr) {
                },
                success: function (data, status, xhr) {
                    if (data.code === 200) {
                        window.location.href = data.data;
                    } else {
                        alert(data.error);
                    }
                },
                error: function (xhr, status) {
                },
                complete: function () {
                }
            })
        });
        $("#wechat").click(function () {
            $.ajax({
                url: url,
                type: 'POST',
                data: {
                    user_id: 1234,
                    shop_id: 11,
                    amount: $("#amount").text(),
                    order_no: randomStr(16),
                    payment: "wechat",
                    callback: "http://",// 回调地址
                    other: {
                        body: 'iPhone 81', // 可选
                        title: '苹果81',// 可选
                        redirect_url: "https://starltd.xingchengfu.com",// 支付成功跳转的页面
                        wap_url: "https://starltd.xingchengfu.com",// 当前h5地址
                        wap_name: '买手机'// 可选 当前h5名字
                    }
                },
                timeout: 5000,
                dataType: 'json',
                beforeSend: function (xhr) {
                },
                success: function (data, status, xhr) {
                    if (data.code === 200) {
                        window.location.href = data.data;
                    } else {
                        alert(data.error);
                    }
                },
                error: function (xhr, status) {
                },
                complete: function () {
                }
            })
        });
    })
</script>
</body>
</html>